<?php
namespace app\common\model;

class Administrator extends Model
{
    protected $hidden = ['password', 'token'];

    protected $searchOptions = [
        'username' => ['like', '%%%s%%'],// 用户名
    ];

    /**
     * 修改器：明文密码转密码散列
     * @param string $value 密码
     * @return string
     */
    public function setPasswordAttr($value)
    {
        return password_hash($value, PASSWORD_DEFAULT);
    }

    /**
     * 用户日志关联
     * @return \think\model\relation\HasMany
     */
    public function log()
    {
        return $this->hasMany(AdministratorLog::class, 'administrator_id', 'id');
    }
}